home *** CD-ROM | disk | FTP | other *** search
- Path: 131.110.50.173!not-for-mail
- From: NS130355@
- Newsgroups: comp.lang.c++
- Subject: ? Accessing members of classes within classes
- Date: 17 Apr 1996 20:27:22 GMT
- Organization: NASA/MSFC
- Message-ID: <4l3k7a$rjo@hammer.msfc.nasa.gov>
- Reply-To: Paul.McKean@maf.nasa.gov
- NNTP-Posting-Host: 131.110.50.173
- X-Newsreader: IBM NewsReader/2 v1.2
-
- What is the proper method of accessing the public members
- of a class used in a "has a" relationship within another
- class as a public member?
-
- Example:
-
- class firstClass
- {
- private: char mydata[10];
-
- public: int setMydata(char *);
- char* getMydata(void);
- }
-
- class secondClass
- {
- private: char mydata2[10];
-
- public: firstClass cMember[10];
- int setMydata2(char *);
- char* getMydata2(void);
- }
-
- int main
- {
- // THIS DOESN'T COMPILE. WHY?
- secondClass myObject;
- myObject.cMember[0].setMydata("HELLO");
-
- // THIS DOES COMPILE
- secondClass* myObject2;
- myObject2->cMember[0].setMydata("HELLO");
-
- return 0;
- }
-
-